var t = getApp()
Page({
  data: {
    iconsUrl:t.globalData.iconsUrl,
    userInfo:wx.getStorageSync('userInfo'),
    info:'',
    navHeight:t.globalData.navHeight, // 导航高度
     // 获取手机号弹窗参数
     show: false,
     duration: 300, //动画时长，单位毫秒
     position: 'bottom',
     round: true,  //是否显示圆角
     overlay: true, //是否显示遮罩层
     customStyle: '',//自定义弹出层样式
     overlayStyle: '', //自定义遮罩层样式
    //  底部菜单
    menuList:[
      {name:'个人信息',type:'1',icon:'gerenxinxi.png'},
      {name:'店主登录',type:'2',icon:'dianzhu-login.png'},
      {name:'洗车教程',type:'3',icon:'xichejiaocheng.png'},
      {name:'用户协议',type:'4',icon:'yonghuxieyi.png'},
      {name:'店主招募',type:'5',icon:'dianzhuzhaomu.png'},
      {name:'联系客服',type:'6',icon:'lianxikefu.png'},
      {name:'平台公告',type:'7',icon:'pingtaigonggao.png'},
      {name:'更新日志',type:'8',icon:'gengxinrizhi.png'},
      {name:'扫码出场',type:'9',icon:'saoma.png'},
		],
		// 洗车教程外部链接
		outUrl:''
  },
  onLoad: function (options) {
    
  },
  onShow(e){
    var that = this
    that.setData({
      userInfo:wx.getStorageSync('userInfo'),
    })
		this.get_info();
		this.get_outUrl();
	},
	// 获取新手指引外链
	get_outUrl(e){
		var that = this
    t.request('/Users/externalLinks',{},function(e){
      if(e.code==200){
				that.setData({
					outUrl:e.result.washing_url
				})
			} 
    })
	},
  // info
  get_info(e){
    var that=this
    t.request('/users/info',{},function(e){
      console.log(e);
      if (e.code==200) {
        that.setData({
          info:e.result
        })
        if(e.result.cars > 0)
        t.globalData.show_login = false;
      }

    })
  },
  // 显示电话登录的弹窗
  showTelLogin(){
    let that = this
    that.setData({show: true})
    // 隐藏底部 tabbar
    wx.hideTabBar({
      animation: false, // 是否需要动画效果，默认为 false
      success: function () {
        console.log('TabBar has been hidden successfully!');
        that.setData({show: true})
      },
      fail: function (err) {
        console.error('Failed to hide TabBar:', err);
      }
    });
  },
  // 登录成功，关闭方法
  exit(){
    this.setData({show: false})
    // 显示底部tabbar
    wx.showTabBar({
      animation: false, // 是否需要动画效果，默认为 false
      success: function () {console.log('TabBar has been hidden successfully!');},
      fail: function (err) {console.error('Failed to hide TabBar:', err);}
    });
  },
  // 手机号 暂不登录按钮
  exitback() {
    this.setData({show: false})
    // 显示底部tabbar
    wx.showTabBar({
      animation: false, // 是否需要动画效果，默认为 false
      success: function () {
        console.log('TabBar has been hidden successfully!');
        wx.switchTab({
          url: '/pages/index/index',
        })       
      },
      fail: function (err) {
        console.error('Failed to hide TabBar:', err);
      }
    });
  },
  //电话登录
  getPhoneNumber(e){
    const that = this,
      iv = e.detail.iv,
      da = e.detail.encryptedData;
    if (!e.detail.encryptedData) return wx.showToast({ title: '授权失败,请重新授权！',icon:'none'})
    // 请求接口
    wx.login({
      success(e){
        console.log(e);
        wx.showLoading({
          title: '请稍后',
        })
        t.request('/login/getPhoneNumber',{code: e.code,iv:iv,encryptedData:da},function(event){
          wx.hideLoading({})
          if (event.code!==200) return wx.showToast({ title: event.msg,icon:'none' })
          if (event.code==200) {
            wx.setStorageSync('tel', event.result.phoneNumber)
            t.globalData.show_tel_login =false
            that.exit(false) //不返回首页
          }
        })
      }
    })
  },
  //菜单跳转
  clickMenu(e){
    let type =  e.currentTarget.dataset.type
    let url = '',tabbarUrl ='';
    console.log('MenuType',type)
    switch(type){
      case '1': //个人信息
        url='personCenter/set/info'
      break;
      case '2': //店主登录
        wx.navigateToMiniProgram({
          appId: 'wxf0da36cc41c62816',
          path: '/pages/index/index'
        })
      break;
			case '3': //洗车教程
				wx.navigateTo({
					url: '/pages/outview/article?url='+this.data.outUrl,
				})
      break;
      case '4': //用户协议
        url='article/article?id=334'
      break;
      case '5': //店主招募
        wx.makePhoneCall({
          phoneNumber: '4000411226',
        })
      break;
      case '6': //联系客服
        url='personCenter/kefu/kefu'
      break;
      case '7': //平台公告
        url='article/article?id=338' 
      break;
      case '8': //更新日志
      url='article/article?id=337'
      break;
      case '9': //扫码出场
        tabbarUrl='scan_door/scan_door'
      break;
      case '101': //洗车记录
        url='order/record'
      break;
      case '102': //充值记录
        url='personCenter/recharge/record';
      break;
      case '103': //核销记录
      url='personCenter/myCoupon/record';
      break;
      case '104': //我的车辆
        url = 'personCenter/myCar/myCar';
      break;
      case '105': //我的分享
        this.show_fake()
      break;
      case '201': //我的余额
        url='personCenter/mySc/mySc';
      break;
      case '202': //我的卡券
        url='personCenter/myCoupon/coupon';
      break;
      case '203': //我的积分
        this.show_fake()
      break;
      case '301': //招募合伙人得广告图
        wx.makePhoneCall({
          phoneNumber: '4000411226',
        })
      break;
      default:
    }
    // 普通页面跳转
    if(url!=""){
      wx.navigateTo({
        url: '/pages/'+url,
      })
    }
    // tabbar页面跳转
    if(tabbarUrl!=""){
      wx.switchTab({
        url: '/pages/'+tabbarUrl,
      })
    }
  },
  // 页面即将上线提示
  show_fake(e){
    wx.showToast({
      title: '即将上线',
      icon:'none'
    })
  },
})